#import "JokeReplyCell.h"

@implementation JokeReplyCell

- (id)init{
    self = [super init];
    if (self) {
        //
    }
    return self;
}

- (void)dealloc
{
    PP_RELEASE(mainView);
    PP_RELEASE(textView);
    PP_RELEASE(nameView);
    PP_RELEASE(floorNumber);
    PP_RELEASE(dotLineImg);
    [super dealloc];
}

-(void)setReplyText:(NSString *)replyText withName:(NSString *)replyName withFloor:(NSString *)replyFloor
{
    // TODO 3 :
    textView.text = [NSString stringWithFormat:@"%@",replyText];
    CGSize labelSize = [replyText sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(267, 10000) lineBreakMode:UILineBreakModeWordWrap];
    float labelHeight = 20;
    if (labelSize.height>20) {
        labelHeight = labelSize.height;
    }
    
    nameView.text = replyName;
    floorNumber.text = replyFloor;
    CGRect textFrame = textView.frame;
    textFrame.size.height = labelHeight;
    textView.frame = textFrame;

    CGRect cellFrame = self.frame;
    self.frame = CGRectMake(cellFrame.origin.x, cellFrame.origin.y, cellFrame.size.width, textView.frame.origin.y+textView.frame.size.height+dotLineImg.frame.size.height+16);
}

- (void)jokeReplyAlignTop {
    CGSize fontSize = [textView.text sizeWithFont:textView.font];
    double finalHeight = fontSize.height * textView.numberOfLines;
    double finalWidth = self.frame.size.width;    //expected width of label
    CGSize theStringSize = [textView.text sizeWithFont:textView.font constrainedToSize:CGSizeMake(finalWidth, finalHeight) lineBreakMode:textView.lineBreakMode];
    int newLinesToPad = (finalHeight  - theStringSize.height) / fontSize.height;
    for(int i=0; i<newLinesToPad; i++)
        textView.text = [textView.text stringByAppendingString:@"\n  "];
}

@end
